package spreadsheet;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.UserDataHandler;

/**
 * @author Ahmed Saliem 
 * this class represents the structure of each cell in the spreadsheet.
 * each cell has a type and value. The type is either primitive or formula.
 */
public class SpreadSheetCell {	
	
	/**
	 *   
	 * 	 each cell has a type that is either primitive or formula
	 */
	public static final String CELL_TYPES_FORMULA = "formula";
	public static final String CELL_TYPES_PRIMITIVE = "primitive";	
	
	/**
	 * cellValue is a string representation of the cell value
	 * which has either a primitive value "real number" or a formula.
	 */
	private String cellValue; 
	/**
	 * cellType: represents the type of the cell which has either 
	 * PRIMITIVE or FORMULA.
	 */
	private String cellType;
	
	/**
	 * default Constructor: give default values to the cell
	 *  default cell type is PRIMITIVE and 
	 *  default cell value is 0.0
	 */
	
	public SpreadSheetCell()
	{
		cellType = CELL_TYPES_PRIMITIVE;
		cellValue = "0.0";
	}
	
	/**
	 * overloaded Constructor
	 */
	public SpreadSheetCell(String cellType, String cellValue)
	{
		this.cellType = cellType;
		this.cellValue = cellValue;
	}
					
	/**
	 * getters and setters
	 */
	public String getCellValue() {
		return cellValue;
	}
        
	public void setCellValue(String cellValue) {
		this.cellValue = cellValue;
	}
        
	public String getCellType() {
		return cellType;
	}
        
	public void setCellType(String cellType) {
		this.cellType = cellType;
	}
        
        @Override
        public String toString() {
            try {
                return FormulaParser.getInstance().parse(cellValue);
            } catch (Exception ex) {}
            return null;
        }
        
        public String toFormulaString() {
            try {
                return cellValue;
            } catch (Exception ex) {}
            return null;
        }
}